/*
* 所有关于用户请求，全部封装在这里
*/
import request from '../utils/request'

// 封装发送登录请求---后续想实现发送请求既调用login方法
export const login = data => {
  return request({
    method: 'POST',
    url: '/app/v1_0/authorizations',
    data
  })
}
// 发送验证码
export const sendCode = mobile => {
  return request({
    method: 'GET',
    url: '/app/v1_0/sms/codes/' + mobile
  })
}

// 获取用户信息
export const getUserInfo = () => {
  return request({
    method: 'GET',
    url: '/app/v1_0/user'
  })
}

// 获取频道列表
export const getChannels = () => {
  return request({
    method: 'GET',
    url: '/app/v1_0/user/channels'
  })
}

/**
 * 关注用户
 */
export const followedUser = target => {
  return request({
    method: 'POST',
    url: '/app/v1_0/user/followings',
    data: {
      target
    }
  })
}
/**
 * 取消关注用户
 * @param {*} target id
 */
export const cancelFollowedUser = target => {
  return request({
    method: 'DELETE',
    url: '/app/v1_0/user/followings/' + target
  })
}

/**
 * 添加收藏
 * @param {*} 文章id
 */
export const addCollect = target => {
  return request({
    method: 'POST',
    url: '/app/v1_0/article/collections',
    data: {
      target
    }
  })
}

/**
 * 取消收藏
 * @param {*} 文章id
 */
export const deleteCollect = target => {
  return request({
    method: 'DELETE',
    url: '/app/v1_0/article/collections/' + target
  })
}
/**
 * 获取用户资料
 * @param {*} 用户id
 */
export const getUserProfile = () => {
  return request({
    method: 'GET',
    url: '/app/v1_0/user/profile'
  })
}
/**
 * 更新用户昵称
 * @param {*} 用户数据
 */
export const updateProfile = (data) => {
  return request({
    method: 'PATCH',
    url: '/app/v1_0/user/profile',
    data
  })
}
/**
 * 更新头像
 */
export const updateUserAvatar = data => {
  return request({
    method: 'PATCH',
    url: '/app/v1_0/user/photo',
    data
  })
}
